<template>
  <div>
    <el-dialog
      title="选择收发货人"
      v-model="show"
      append-to-body
    >
      <el-form
        :model="query"
        :inline="true"
        class="form"
      >
        <el-form-item>
          <el-input
            v-model="query.title"
            placeholder="请输入"
          > </el-input>
        </el-form-item>
        <el-form-item style="margin-left: 8px">
          <el-button
            type="primary"
            @click="search"
          > 搜索 </el-button>
        </el-form-item>
      </el-form>
      <AppPageTable
        stripe
        :data="tableData.data"
        @change="getTableData()"
        :autostyle="'height: 300px'"
        :option="tableData.option"
      >
        <el-table-column
          prop="entName"
          label="客户简称"
        />
        <el-table-column
          prop="type"
          label="收发通类型"
        >
          <template #default="scope">
            {{ parseType(scope.row.type) }}
          </template>
        </el-table-column>
        <el-table-column
          prop="title"
          label="抬头信息"
        />
        <el-table-column
          label="操作"
          width="90px"
          fixed="right"
        >
          <template #default="scope">
            <el-button
              @click="choose(scope.row.title)"
              link
              type="primary"
            >选取</el-button>
          </template>
        </el-table-column>
      </AppPageTable>
    </el-dialog>
  </div>
</template>

<script>
import { defineComponent } from "vue";
import AppSearchForm from "@/components/AppSearchForm.vue";
import AppPageTable, { useTableOption } from "@/components/AppPageTable2";
export default defineComponent({
  components: {
    AppPageTable,
    AppSearchForm,
  },
  props: {
    inKey: {
      type: Number,
      default: 0,
    },
  },
  emits: ["choose"],
  data() {
    return {
      show: false,
      tableData: {
        data: [],
        option: useTableOption({
          pageSize: 5,
          pageSizes: [5, 10, 20],
        }),
      },
      query: {
        title: "",
      },
      entID: "",
    };
  },
  methods: {
    open(id) {
      this.show = true;
      this.entID = id;
      this.$nextTick(() => {
        this.getTableData();
      });
    },
    getTableData() {
      this.tableData.option.loading = true;
      this.$http
        .get("/api/bubltitlehistory/query", {
          Title: this.query.title,
          Type: this.inKey,
          EntId: this.entID,
          PageIndex: this.tableData.option.page,
          PageSize: this.tableData.option.pageSize,
        })
        .then((res) => {
          this.tableData.data = res.content;
          this.tableData.option.total = res.totalElements;
        })
        .finally(() => {
          this.tableData.option.loading = false;
        });
    },
    search() {
      this.tableData.option.page = 1;
      this.getTableData();
    },
    choose(data) {
      this.$emit("choose", data);
      this.show = false;
    },
    parseType(type) {
      if (type == 1) {
        return "发货人"
      } else if (type == 2) {
        return "收货人"
      } else if (type == 3) {
        return "通知人"
      } else if (type == 4) {
        return "海外代理"
      } else if (type == 5) {
        return "第二通知人"
      }
    }
  },
  mounted() { },
});
</script>

<style lang="scss" scoped>
.form {
  :deep(.el-form-item) {
    width: auto !important;
  }
}
</style>
